/*
 * cm_yuv422p.h
 *
 *  Created on: 2014年5月26日
 *      Author: chens
 */

#ifndef CM_YUV422P_H_
#define CM_YUV422P_H_

#include <cm/img/cm_img.h>

static inline size_t yuv422p_data_total(unsigned w, unsigned h)
{
	return (w * h * 2);
}

static inline int yuv422p_y_offset(unsigned x, unsigned y, unsigned w,
		unsigned h)
{
	if (VALID_AREA(x, y, w, h))
		return (int) (y * w + x);
	else
		return -1;
}

static inline int yuv422p_u_offset(unsigned x, unsigned y, unsigned w,
		unsigned h)
{
	if (VALID_AREA(x, y, w, h))
		return (int) ((w * h) + (y * w /2) + x/2);
	else
		return -1;
}

static inline int yuv422p_v_offset(unsigned x, unsigned y, unsigned w,
		unsigned h)
{
	if (VALID_AREA(x, y, w, h))
		return (int) ((w * h) + (w * h / 2) + (y * w / 2) + x / 2);
	else
		return -1;
}

#endif /* CM_YUV422P_H_ */
